package com.it.administrator.okhttputils;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.it.administrator.okhttputils.application.Entity;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.ResultCallback;
import com.lzy.okgo.callback.StringCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {


    @BindView(R.id.tv_1)
    TextView tv1;
    @BindView(R.id.tv_2)
    TextView tv2;

    String url=
            "http://210.75.207.51:7001/Meteorological/power_powerObserve.action?type=wind&areacode=&level=500kV";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
       tv1.setOnClickListener(this);
       tv2.setOnClickListener(this);

    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onStop() {
        super.onStop();
    }


    @OnClick({R.id.tv_1, R.id.tv_2})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_1:
                OkGo.get(url).tag("1").execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, Call call, Response response) {
                        System.out.println("s__________"+s);
                    }

                    @Override
                    public void onError(Call call, Response response, Exception e) {
                        super.onError(call, response, e);
                    }
                });
                break;
            case R.id.tv_2:
            /*    OkGo.get(url).tag("2").execute(new EntityCallback<enti>() {
                });*/
   OkGo.get(url).tag("2").cacheTime(3*60*1000).cacheMode(CacheMode.REQUEST_FAILED_READ_CACHE).execute(new ResultCallback<Entity>() {


       @Override
       public void onSuccess(Entity entity, Call call, Response response) {

           System.out.println("________"+entity.time);
       }
   });

                break;
        }
    }


}
